<!doctype html>
<html class="x-admin-sm">
<#include "../header.ftl">
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <input type="hidden" id="id" value="${(user.id)!}" name="id">
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>登录名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${(user.username)!}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>
            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="x-red">*</span>手机
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="mobile" name="mobile" required=""
                           autocomplete="off" class="layui-input" value="${(user.mobile)!}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    备注
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="common" name="common" required=""
                           autocomplete="off" class="layui-input" value="${(user.common)!}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button class="layui-btn" lay-filter="add" lay-submit="">
                    保存
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            // nikename: function(value) {
            //     if (value.length < 5) {
            //         return '昵称至少得5个字符啊';
            //     }
            // }
        });

        //监听提交
        form.on('submit(add)', function (data) {
            console.log(data);
            $.ajax({
                type: "POST",                      //请求类型
                url: "./userEdit?v=save",                 //URL
                data: data.field,                  //传递的参数
                dataType: "json",                 //返回的数据类型
                success: function (data) {          //data就是返回的json类型的数据
                    console.log(JSON.stringify(data));
                    if (data.code == 1) {
                        layer.alert("操作成功", {icon: 6}, function () {
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });
                    } else {
                        layer.msg(data.msg)
                    }
                },
                error: function (data) {
                }
            });
            return false;
        });

    });
</script>
</body>
</html>